package org.sunsys.qa.service.user;

import org.sunsys.qa.service.Service;
import org.sunsys.qa.service.response.ResponseStatus;
import org.sunsys.qa.service.response.UserRegistrationResponse;
import org.sunsys.qa.txnhandler.UserTxnsHandler;
import org.sunsys.qa.user.UserRegistrationDto;
import org.sunsys.qa.user.exceptions.UserIdAlreadyExistedException;



public class UserRegistrationService implements Service<UserRegistrationDto, UserRegistrationResponse> {

	private UserTxnsHandler userTxnsHandler = null;
	
	public UserRegistrationService() {
		this.userTxnsHandler = new UserTxnsHandler();
	}
	
	public void setUserTxnsHandler(UserTxnsHandler userTxnsHandler) {
		this.userTxnsHandler = userTxnsHandler;
	}
	
	public UserTxnsHandler getUserTxnsHandler() {
		return userTxnsHandler;
	}
	
	@Override
	public UserRegistrationResponse service(UserRegistrationDto userRegistrationDto) 
		throws UserIdAlreadyExistedException {
		
		//TODO insert the record in user table
		/*
		 * 1.	use Transactions handler to register the user
		 */
		
		userTxnsHandler.registerUser(userRegistrationDto);
		UserRegistrationResponse registrationResponse = new UserRegistrationResponse();
		
		registrationResponse.setUserId(userRegistrationDto.getUserId());
		registrationResponse.setStatus(ResponseStatus.SUCCESS);
		registrationResponse.setStatusMessage("Congracts. Registration successful");
		
		return registrationResponse;
	}
}
